#!/usr/bin/env python -OO
# -*- coding: utf-8 -*-

# Copyright © 2008,2009 Trust Digital Technology Laboratory, Shanghai Jiao Tong University.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Author:
#   XING Dong sheng <homer.xing@gmail.com>

from sendkey import sendkey
import controlmouse
from waitwindow import waitwindow
import time
import threading

class auto_firestarter(threading.Thread):
	def run(self):
		Delay=0 #调试用的
		waitwindow('firestarter')

		sendkey('Alt F'); time.sleep(Delay)
		sendkey('Alt F'); time.sleep(Delay)
		sendkey('Alt F'); time.sleep(Delay)
		sendkey('Tab');   time.sleep(Delay)
		sendkey('Space'); time.sleep(Delay)
		sendkey('Alt S'); time.sleep(Delay)
		sendkey('Alt Q'); time.sleep(Delay)
		#有时会出现“eth0没有准备好”的错误
		sendkey('Alt O'); time.sleep(Delay)
		sendkey('Alt F4');time.sleep(Delay)#把窗口关上

class auto_eioffice(threading.Thread):
	def run(self):
		Delay=1
		waitwindow('emo.inl.eioxpack.dispose.Disposer')

		sendkey('Alt N'); time.sleep(Delay) #FIXME 这个不起作用 -_-b
		sendkey('Alt N'); time.sleep(Delay)
		sendkey('Shift Tab'); time.sleep(Delay)
		sendkey('Space'); time.sleep(Delay)
		sendkey('Alt N'); time.sleep(Delay)
		sendkey('Alt N'); time.sleep(Delay)
		sendkey('Alt N'); time.sleep(Delay)
		#FIXME 计时很不精确！所以以下这几行暂时不用，而用手工完成安装。
		#time.sleep(10) #等待安装过程结束
		#sendkey('Alt N'); time.sleep(Delay)
		#sendkey('Alt N')
		#time.sleep(25) #等待安装过程结束
		#sendkey('Space')

class auto_eioffice_upgrade(threading.Thread):
	def run(self):
		waitwindow('upgrade-Main')
		sendkey("\n")

class auto_netbeans(threading.Thread):
	def run(self):
		Delay=2 #JAVA GUI响应很慢。不要改成0。
		waitwindow('org-netbeans-installer-Installer')
		time.sleep(5)
		sendkey("Alt C"); time.sleep(Delay)
		m=controlmouse.ControlMouse()
		w,h=m.get_screen_resolution()
		m.mouse_move(w/2,h/2)
		m.mouse_click(1)
		#取消“Open ESB”“Glass Fish”和“SOA”
		sendkey("End"); time.sleep(Delay)
		sendkey("Space"); time.sleep(Delay)
		sendkey("Up"); time.sleep(Delay)
		sendkey("Up"); time.sleep(Delay)
		sendkey("Space"); time.sleep(Delay)
		sendkey("Up"); time.sleep(Delay)
		sendkey("Space"); time.sleep(Delay)
		sendkey("Up"); time.sleep(Delay)
		sendkey("Up"); time.sleep(Delay)
		sendkey("Space"); time.sleep(Delay)
		sendkey("Alt O"); time.sleep(Delay)
		sendkey("Alt N"); time.sleep(Delay)
		sendkey("Alt A"); time.sleep(Delay)
		sendkey("Alt N"); time.sleep(Delay)
		sendkey("Alt I"); time.sleep(Delay)
		#FIXME 需要等一段时间再按下Alt F
		sendkey("Alt F")
